﻿using System.IO;
using Wolfpack.Contrib.DashboardAdapter.Formatters;
using Wolfpack.Contrib.DashboardAdapter.Interfaces;
using Wolfpack.Contrib.DashboardAdapter.Repository;
using Wolfpack.Core;
using Wolfpack.Core.Interfaces;

namespace Wolfpack.Contrib.DashboardAdapter.Periscope.Formatters
{
    public class PeriscopeTemplatePublisherBootstrapper : ISupportBootStrapping<PeriscopeTemplatePublisherConfig>
    {
        public void Execute(PeriscopeTemplatePublisherConfig config)
        {
            if (!Container.IsRegistered<ITemplateRespository>())
            {
                Logger.Debug("Registering '{0}' as default '{1}'", typeof(FileSystemTemplateRepository).Name,
                    typeof(ITemplateRespository).Name);

                var folder = SmartLocation.GetLocation(@"dashboard\templates");
                Directory.CreateDirectory(folder);

                var templateRepository = new FileSystemTemplateRepository(folder);
                Container.RegisterInstance<ITemplateRespository>(templateRepository);
            }

            if (!Container.IsRegistered<IMessageFormatter>())
            {
                Logger.Debug("Registering '{0}' as default '{1}'", typeof(DotLiquidTemplateFormatter).Name,
                    typeof(IMessageFormatter).Name);
                Container.RegisterInstance<IMessageFormatter>(new DotLiquidTemplateFormatter());
            }
        }
    }
}